<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /**
         *  // index   0 1 2 3 4 5
         *  //  i  0 1 2
         * 
         *  // 对调关系：
         *   i              6
         *   0     5  arr.length - 1 - i
         *   1     4  arr.length - 1 - i
         *   2     3  arr.length - 1 - i
         * 
         *  var arr = [1,2,3,4,5,6]; // ===> [6,5,4,3,2,1]
         *  
         *  length 6 翻转 3次   arr.length  / 2  = 3
         *  [6,2,3,4,5,1]
         *  [6,5,3,4,2,1]
         *  [6,5,4,3,2,1]
         * 
         *  var arr2 = [1,2,3,4,5,6,7]; ==> [7,6,5,4,3,2,1]
         *  
         *  length 7 翻转3次  parseInt(arr.length / 2) = 3
         *  [7,2,3,4,5,6,1]
         *  [7,6,3,4,5,2,1]
         *  [7,6,5,4,3,2,1]
         * 
         *  1. 循环翻转的次数跟数组的长度有关
         *  2. 对调的索引，要找对公式关系
         *  3. 如何将两个元素进行对调
         *  
         */
        var arr = [1,2,3,4,5,6,7];
        for(var i = 0; i < parseInt(arr.length / 2); i++){
            // i  0  1  2
            var temp = arr[i];
            arr[i] = arr[arr.length - 1 - i];
            arr[arr.length - 1 - i] = temp;
        }
        console.log(arr);

        // var a = 1;
        // var b = 2;
        // var t = a;
        // a = b;
        // b = t;
    </script>
</body>
</html>